﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using _1241118_DoAn_hqtcsdl.QuanLyGaSGDataSetTableAdapters;

namespace _1241118_DoAn_hqtcsdl
{
    public partial class NhanVienQuanLy : Form
    {
        SELECT_THONGTINCHUYENTAUTableAdapter thongTinChuyenAdapter;
        SEARCH_THEOMOTAGATableAdapter thongTinMoTaGaAdapter;
       
       
                
        public NhanVienQuanLy()
        {
            InitializeComponent();
            dtpGioDi.Format = DateTimePickerFormat.Custom;
            dtpGioDi.CustomFormat = "dd.MM.yyyy HH:mm";
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "dd.MM.yyyy HH:mm";
            fillTable(this.dtgvThongTinChuyen);
            fillTable(this.dtgvThongTinChuyen2);
            fillTable_1(this.dtgvThongTinMoTaGa);
        }

        private void thêmChuyếnTàuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = true;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            dtgvThongTinChuyen.Visible = true;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            fillTable(this.dtgvThongTinChuyen);
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void btnThemChuyen_Click(object sender, EventArgs e)
        {
            string maTau = cbMaTau.SelectedValue.ToString();
            string maLoaiChuyen = cbMaLoaiChuyen.SelectedValue.ToString();
            string diemDi = lbDiemDi.Text;
            string diemDen = cbDDDen1.SelectedValue.ToString();
            DateTime gioDi = dtpGioDi.Value;
                       
            int i = thongTinChuyenAdapter.INSERTINFOCHUYENTAU_FULL(maTau, maLoaiChuyen, gioDi, diemDi, diemDen);

            if (i != 0)
            {
                MessageBox.Show("Thêm chuyến thành công !");
                fillTable(this.dtgvThongTinChuyen);
                fillTable(this.dtgvThongTinChuyen2);
            }

        }

        private void NhanVienQuanLy_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'quanLyGaSGDataSet.MoTaLoaiChuyen' table. You can move, or remove it, as needed.
            this.moTaLoaiChuyenTableAdapter.Fill(this.quanLyGaSGDataSet.MoTaLoaiChuyen);
            // TODO: This line of code loads data into the 'quanLyGaSGDataSet.SELECT_MACHUYEN' table. You can move, or remove it, as needed.
            this.sELECT_MACHUYENTableAdapter.Fill(this.quanLyGaSGDataSet.SELECT_MACHUYEN);
            // TODO: This line of code loads data into the 'quanLyGaSGDataSet.SELECT_DDDEN' table. You can move, or remove it, as needed.
            this.sELECT_DDDENTableAdapter.Fill(this.quanLyGaSGDataSet.SELECT_DDDEN);
            // TODO: This line of code loads data into the 'quanLyGaSGDataSet.SELECT_MALC' table. You can move, or remove it, as needed.
            this.sELECT_MALCTableAdapter.Fill(this.quanLyGaSGDataSet.SELECT_MALC);          
            // TODO: This line of code loads data into the 'quanLyGaSGDataSet.SELECT_MATAU' table. You can move, or remove it, as needed.
            this.sELECT_MATAUTableAdapter.Fill(this.quanLyGaSGDataSet.SELECT_MATAU);
            this.sEARCH_THEOMOTAGATableAdapter.Fill(this.quanLyGaSGDataSet.SEARCH_THEOMOTAGA);
        }

        private void fillTable(DataGridView myTable)
        {
            thongTinChuyenAdapter = new SELECT_THONGTINCHUYENTAUTableAdapter();
            DataTable thongTinChuyenDT = thongTinChuyenAdapter.GetData();

            myTable.DataSource = thongTinChuyenDT;
        }

        private void fillTable_1(DataGridView myTable_1)
        {
            thongTinMoTaGaAdapter = new SEARCH_THEOMOTAGATableAdapter();
            DataTable thongMoTaGaDT = thongTinMoTaGaAdapter.GetData();

            myTable_1.DataSource = thongMoTaGaDT;

        }
        

        private void xóaChuyếnTàuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = true;
            gbCapNhatChuyen.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = true;
            dtgvThongTinMoTaGa.Visible = false;
            lbMCCanXoa.Text = "";
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void btnXoaChuyen_Click(object sender, EventArgs e)
        {               
            string maChuyen = lbMCCanXoa.Text;
            if (!maChuyen.Equals(""))
            {
              
                int i = thongTinChuyenAdapter.DELETE_THONGTINCHUYENTAU(maChuyen);

                if (i != 0)
                {
                    MessageBox.Show("Xóa thành công chuyến tàu " + maChuyen + "!");
                    fillTable(this.dtgvThongTinChuyen);
                    fillTable(this.dtgvThongTinChuyen2);
                    lbMCCanXoa.Text = "";                  
                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn mã chuyến!");
            }            
        }

        private void cậpNhậtChuyếnTàuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = true;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = true;
            dtgvThongTinMoTaGa.Visible = false;
            //lbMC.Text = "";
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }


        private void btnSuaChuyen_Click(object sender, EventArgs e)
        {
            string maChuyen = lbMC.Text;
            string maTauMoi = comboBox1.SelectedValue.ToString();
            string maLoaiChuyenMoi = comboBox2.SelectedValue.ToString();
            string diemDi = label11.Text;
            string diemDenMoi = cbDDDen2.SelectedValue.ToString();
            DateTime gioDiMoi = dateTimePicker1.Value;
            try
            {
                thongTinChuyenAdapter = new SELECT_THONGTINCHUYENTAUTableAdapter();
                int i = thongTinChuyenAdapter.UPDATE_THONGTINCHUYENTAU(maTauMoi, maChuyen, maLoaiChuyenMoi, gioDiMoi, diemDi, diemDenMoi);

                if (i != 0)
                {
                    MessageBox.Show("Cập nhật chuyến " + maChuyen + " thành công !");
                    fillTable(this.dtgvThongTinChuyen2);
                }                           
            }catch(Exception)
            {
                MessageBox.Show("Không cập nhật chuyến được !");
            }
        }

        private void dtgvThongTinChuyen2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int cIndex = int.Parse(dtgvThongTinChuyen2.SelectedRows[0].Index.ToString());

            string maChuyen = dtgvThongTinChuyen2.Rows[cIndex].Cells[1].Value.ToString();


            if (gbXoaChuyen.Visible)
            {
                lbMCCanXoa.Text = maChuyen;
            }
            else if (gbCapNhatChuyen.Visible)
            {
                lbMC.Text = maChuyen;
                comboBox1.SelectedValue = dtgvThongTinChuyen2.Rows[cIndex].Cells[0].Value.ToString();
                comboBox2.SelectedValue = dtgvThongTinChuyen2.Rows[cIndex].Cells[2].Value.ToString();
                dtpGioDi.Value = DateTime.Parse(dtgvThongTinChuyen2.Rows[cIndex].Cells[3].Value.ToString());
                cbDDDen2.SelectedValue = dtgvThongTinChuyen2.Rows[cIndex].Cells[6].Value.ToString();
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            SELECT_THONGTINCHUYENTAUTableAdapter adapter = new SELECT_THONGTINCHUYENTAUTableAdapter();
            DataTable resultDT = new DataTable();
            string keyword = "";

            if (label30.Text.Equals("Mã Loại Chuyến: "))
            {
                keyword = cbMLC.SelectedValue.ToString();

                resultDT = adapter.GetDataByMLC(keyword);

                if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinChuyen.DataSource = resultDT;
                    dtgvThongTinChuyen.Visible = true;
                }
                else
                {
                    MessageBox.Show("Không tìm thấy !");
                }
            }

            else if ((label30.Text.Equals("Mã Chuyến: ")))
            {
                keyword = cbMCH.SelectedValue.ToString();
                
                resultDT = adapter.GetDataByMaChuyen(keyword);

                if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinChuyen.DataSource = resultDT;
                    dtgvThongTinChuyen.Visible = true;
                }
                else
                {
                    MessageBox.Show("Không tìm thấy !");
                }
            }

            else if ((label30.Text.Equals("Mã Tàu: ")))
            {
                keyword = cbMTau.SelectedValue.ToString();

                resultDT = adapter.GetDataByMTau(keyword);

                if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinChuyen.DataSource = resultDT;
                    dtgvThongTinChuyen.Visible = true;
                }
                else
                {
                    MessageBox.Show("Không tìm thấy !");
                }
            }

            else if ((label30.Text.Equals("Thời Gian Đi: ")))
            {
                int ngay = int.Parse(cbNgay.SelectedItem.ToString());
                int thang = int.Parse(cbThang.SelectedItem.ToString());
                int nam = int.Parse(cbNam.SelectedItem.ToString());

                resultDT = adapter.GetDataByNTNam(ngay, thang, nam);

                if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinChuyen.DataSource = resultDT;
                    dtgvThongTinChuyen.Visible = true;
                }
                else
                {
                    MessageBox.Show("Không tìm thấy !");
                }
            }

            else if ((label30.Text.Equals("Địa Điểm Đến: ")))
            {
                keyword = cbDDDen.SelectedValue.ToString();

                resultDT = adapter.GetDataByDDDen(keyword);

                if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinChuyen.DataSource = resultDT;
                    dtgvThongTinChuyen.Visible = true;
                }
                else
                {
                    MessageBox.Show("Không tìm thấy !");
                }

            }
        }
            
        private void tìmTheoMãChuyếnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = true;
            gbTraCuuGiaVe.Visible = false;
            label30.Visible = true;
            lbMoTaGa.Visible = false;
            label30.Text = "Mã Chuyến: ";
            cbMLC.Visible = false;
            cbMCH.Visible = true;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;           
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void tìmTheoMãLoạiChuyếnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = true;
            gbTraCuuGiaVe.Visible = false;
            label30.Visible = true;
            lbMoTaGa.Visible = false;
            label30.Text = "Mã Loại Chuyến: ";
            cbMLC.Visible = true;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;         
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void tìmTheoMãTàuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = true;
            gbTraCuuGiaVe.Visible = false;
            label30.Visible = true;
            lbMoTaGa.Visible = false;
            label30.Text = "Mã Tàu: ";
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = true;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;          
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void tìmTheoThờiGianĐiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = true;
            gbTraCuuGiaVe.Visible = false;
            label30.Visible = true;
            lbMoTaGa.Visible = false;
            label30.Text = "Thời Gian Đi: ";
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = true;
            cbNgay.Text = "1";
            cbThang.Visible = true;
            cbThang.Text = "1";
            cbNam.Visible = true;
            cbNam.Text = "2013";
            cbDDDen.Visible = false;            
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void tìmTheoĐịaĐiểmĐếnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = true;
            gbTraCuuGiaVe.Visible = false;
            lbMoTaGa.Visible = false;
            label30.Visible = true;
            label30.Text = "Địa Điểm Đến: ";
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = true;            
            lbMoTaGa.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }
//--------------------------------------------------------------------
        private void traCứuGiáVéToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = true;
            lbMoTaGa.Visible = true;
            label30.Visible = false;
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;
            cbMoTaGa.Visible = true;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            lbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }
        private void btTimMoTaGa_Click(object sender, EventArgs e)
        {
            SEARCH_THEOMOTAGATableAdapter adapter = new SEARCH_THEOMOTAGATableAdapter();
            DataTable resultDT = new DataTable();
            string keyword = "";           
            keyword = cbMoTaGa.SelectedValue.ToString();

            resultDT = adapter.GetDataByMoTaGa(keyword);

            if (resultDT.Rows.Count != 0)
                {
                    dtgvThongTinMoTaGa.DataSource = resultDT;
                    dtgvThongTinMoTaGa.Visible = true;
                }
            else
                {
                    MessageBox.Show("Không tìm thấy !");
                }         
        }

        private void cộngThêmTiềnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            lbMoTaGa.Visible = false;
            label30.Visible = false;
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = true;
            cbMoTaGa_1.Visible = true;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void btnSuaGia_1_Click(object sender, EventArgs e)
        {
            string dd = cbMoTaGa_1.SelectedValue.ToString();

            if ((txtThemTien.Text.Length) == 0)
            {
                MessageBox.Show("Vui lòng nhập số tiền thêm!");
            }
            else
            {
                double soTienThem = Double.Parse(txtThemTien.Text);
                DanhSachGaTableAdapter myDSGAdapter = new DanhSachGaTableAdapter();
                int i = myDSGAdapter.USP_UPDATE_GIA_1(dd, soTienThem);
           
                 if (i != 0)
                 {
                    MessageBox.Show("Cập nhật giá thành công!");
                    fillTable_1(this.dtgvThongTinMoTaGa);
                    dtgvThongTinMoTaGa.Visible = true;
                 }         
            }            
        }

        private void trừBớtTiềnGVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            lbMoTaGa.Visible = false;
            label30.Visible = false;
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = true;
            cbMoTaGa_2.Visible = true;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void btnSuaGia_2_Click(object sender, EventArgs e)
        {
            string dd = cbMoTaGa_2.SelectedValue.ToString();
            if ((txtGiamTien.Text.Length) == 0)
            {
                MessageBox.Show("Vui lòng nhập số tiền giảm!");
            }
            else
            {
                double soTienGiam = Double.Parse(txtGiamTien.Text);
                DanhSachGaTableAdapter myDSGAdapter = new DanhSachGaTableAdapter();
                double giaVE = (Double)myDSGAdapter.LayGiaVe(dd);

                if (soTienGiam <= giaVE)
                {
                    int i = myDSGAdapter.USP_UPDATE_GIA_2(dd, soTienGiam);
                    if (i != 0)
                    {
                        MessageBox.Show("Cập nhật giá thành công!");
                        fillTable_1(this.dtgvThongTinMoTaGa);
                        dtgvThongTinMoTaGa.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("Số tiền giảm không thể lớn hơn giá vé!!!");
                }
            }
        }

        private void cộngThêmThờiGianToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            lbMoTaGa.Visible = false;
            label30.Visible = false;
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = true;
            cbMoTaGa_3.Visible = true;
            gbGiamGio.Visible = false;
            cbMoTaGa_4.Visible = false;
        }

        private void btnSuaThoiGian_1_Click(object sender, EventArgs e)
        {
            string dd = cbMoTaGa_3.SelectedValue.ToString();
            if ((txtThemGio.Text.Length) == 0)
            {
                MessageBox.Show("Vui lòng nhập số giờ thêm!");
            }
            else
            {
                int soGioThem = int.Parse(txtThemGio.Text);
                DanhSachGaTableAdapter myDSGAdapter = new DanhSachGaTableAdapter();
                int i = myDSGAdapter.USP_UPDATE_TG_1(dd, soGioThem);

                if (i != 0)
                {
                    MessageBox.Show("Cập nhật thời gian thành công!");
                    fillTable_1(this.dtgvThongTinMoTaGa);
                    dtgvThongTinMoTaGa.Visible = true;
                }
            }
        }

        private void trừBớtThờiGianToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gbThemChuyen.Visible = false;
            gbXoaChuyen.Visible = false;
            gbCapNhatChuyen.Visible = false;
            dtgvThongTinChuyen.Visible = false;
            dtgvThongTinChuyen2.Visible = false;
            dtgvThongTinMoTaGa.Visible = false;
            gbTimChuyen.Visible = false;
            gbTraCuuGiaVe.Visible = false;
            lbMoTaGa.Visible = false;
            label30.Visible = false;
            cbMLC.Visible = false;
            cbMCH.Visible = false;
            cbMTau.Visible = false;
            cbNgay.Visible = false;
            cbThang.Visible = false;
            cbNam.Visible = false;
            cbDDDen.Visible = false;
            cbMoTaGa.Visible = false;
            gbThemTien.Visible = false;
            cbMoTaGa_1.Visible = false;
            gbGiamTien.Visible = false;
            cbMoTaGa_2.Visible = false;
            gbThemGio.Visible = false;
            cbMoTaGa_3.Visible = false;
            gbGiamGio.Visible = true;
            cbMoTaGa_4.Visible = true;
        }

        private void btnSuaThoiGian_2_Click(object sender, EventArgs e)
        {
            string dd = cbMoTaGa_4.SelectedValue.ToString();
            if ((txtGiamGio.Text.Length) == 0)
            {
                MessageBox.Show("Vui lòng nhập số giờ giảm!");
            }
            else
            {
                int soGioGiam = int.Parse(txtGiamGio.Text);
                DanhSachGaTableAdapter myDSGAdapter = new DanhSachGaTableAdapter();
                int Gio = (int)myDSGAdapter.LayGio(dd);

                if (soGioGiam <= Gio)
                {
                    int i = myDSGAdapter.USP_UPDATE_TG_2(dd, soGioGiam);

                    if (i != 0)
                    {
                        MessageBox.Show("Cập nhật thời gian thành công!");
                        fillTable_1(this.dtgvThongTinMoTaGa);
                        dtgvThongTinMoTaGa.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("Số giờ giảm không thể lớn hơn thời gian để đi!!!");
                }
            }
        }
        private void NhanVienQuanLy_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }    
}
